﻿<template>
  <a-card :bordered="false">
    <div class="table-operator">
      <a-button v-if="hasPerm('Base_VIPUserOrder.Add')" type="primary" icon="plus" @click="handleAdd()">新建</a-button>
      <a-button
        v-if="hasPerm('Base_VIPUserOrder.Delete')"
        type="primary"
        icon="minus"
        @click="handleDelete(selectedRowKeys)"
        :disabled="!hasSelected()"
        :loading="loading"
      >删除
      </a-button>
      <a-button type="primary" icon="redo" @click="getDataList()">刷新</a-button>
    </div>

    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="10">
          <a-col :md="4" :sm="24">
            <a-form-item label="查询类别">
              <a-select allowClear v-model="queryParam.condition">
                <!--<a-select-option key="CreatorId">VIP用户手机号</a-select-option>-->
                <a-select-option key="ProjectName">项目名称</a-select-option>
                <a-select-option key="BuildingType">建筑类型</a-select-option>
                <a-select-option key="City">项目城市</a-select-option>
                <!--<a-select-option key="OrderType">订单类型</a-select-option>-->
                <!--<a-select-option key="Remark">备注</a-select-option>-->
                <!--<a-select-option key="Formats">业态详情</a-select-option>-->
                <!--a-select-option key="Elevators">电梯详情</a-select-option>-->
                <!--<a-select-option key="Files">上传文件Url</a-select-option>-->
                <!--<a-select-option key="ReportUrl">生成报告文件地址</a-select-option>-->
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="4" :sm="24">
            <a-form-item>
              <a-input v-model="queryParam.keyword" placeholder="关键字" />
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="24">
            <a-button type="primary" @click="() => {this.pagination.current = 1; this.getDataList()}">查询</a-button>
            <a-button style="margin-left: 8px" @click="() => (queryParam = {})">重置</a-button>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <a-table
      ref="table"
      :scroll="{y:530}"
      :columns="columns"
      :rowKey="row => row.Id"
      :dataSource="data"
      :pagination="pagination"
      :loading="loading"
      @change="handleTableChange"
      :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
      :bordered="true"
      size="small"
    >
      <span slot="CreateTime" slot-scope="CreateTime">{{ timeFormat(CreateTime) }}</span>
      <span slot="orderType" slot-scope="text">
        <span v-if="text == '0'">算运力</span>
        <span v-if="text == '1'">查井道</span>
      </span>
      <span slot="status" slot-scope="text">
        <template>
          <a-tag v-if="text == '1'" color="red">计算中</a-tag>
          <a-tag v-else-if="text == '2'" color="green">已完成</a-tag>
        </template>
      </span>
      <span slot="action" slot-scope="text, record">
        <template>
          <a v-if="hasPerm('Base_VIPUserOrder.Edit')" @click="handleEdit(record.Id)">编辑</a>
          <a-divider v-if="hasPerm('Base_VIPUserOrder.Edit')&&hasPerm('Base_VIPUserOrder.Delete')" type="vertical" />
          <a v-if="hasPerm('Base_VIPUserOrder.Delete')" @click="handleDelete([record.Id])">删除</a>
        </template>
      </span>
    </a-table>

    <edit-form ref="editForm" :parentObj="this"></edit-form>
  </a-card>
</template>

<script>
import EditForm from './EditForm'
import moment from 'moment'

const columns = [
  // { title: '排序', dataIndex: 'Sort', width: '3%' },
  { title: '订单编号', dataIndex: 'Id' },
  { title: '订单类型', dataIndex: 'OrderType', scopedSlots: { customRender: 'orderType' } },
  { title: '项目名称', dataIndex: 'ProjectName' },
  { title: '创建时间', dataIndex: 'CreateTime', scopedSlots: { customRender: 'CreateTime' } },
  { title: '项目城市', dataIndex: 'City' },
  { title: '建筑类型', dataIndex: 'BuildingType' },
  // { title: '总建筑面积', dataIndex: 'TotalArea' },
  // { title: '标准建筑面积', dataIndex: 'StandardArea' },
  // { title: '建筑总高度', dataIndex: 'Height' },
  // { title: '备注', dataIndex: 'Remark', width: '10%' },
  // { title: '业态详情', dataIndex: 'Formats', width: '10%' },
  // { title: '电梯详情', dataIndex: 'Elevators', width: '10%' },
  // { title: '上传文件Url', dataIndex: 'FilesUrl', width: '10%' },
  // { title: '生成报告文件地址', dataIndex: 'ReportUrl', width: '10%' },
  { title: '状态', dataIndex: 'Status', scopedSlots: { customRender: 'status' } },
  { title: '操作', dataIndex: 'action', scopedSlots: { customRender: 'action' } }
]

export default {
  components: {
    EditForm
  },
  mounted () {
    this.getDataList()
  },
  data () {
    return {
      data: [],
      pagination: {
        current: 1,
        pageSize: 20,
        showTotal: (total, range) => `总数:${total} 当前:${range[0]}-${range[1]}`,
        pageSizeOptions: ['10', '20', '30', '40', '50', '100'], // 设置pageSize的可选值，页面啊可以通过下拉框进行选择
        showSizeChanger: true
      },
      filters: {},
      sorter: { field: 'Id', order: 'desc' },
      loading: false,
      columns,
      queryParam: {},
      selectedRowKeys: []
    }
  },
  methods: {
    handleTableChange (pagination, filters, sorter) {
      this.pagination = { ...pagination }
      this.filters = { ...filters }
      this.sorter = { ...sorter }
      this.getDataList()
    },
    getDataList () {
      this.selectedRowKeys = []

      this.loading = true
      this.$http
        .post('/Base_VIPUser/Base_VIPUserOrder/GetDataList', {
          PageIndex: this.pagination.current,
          PageRows: this.pagination.pageSize,
          SortField: this.sorter.field || 'Id',
          SortType: this.sorter.order || 'desc',
          Search: this.queryParam,
          ...this.filters
        })
        .then(resJson => {
          this.loading = false
          this.data = resJson.Data
          if (this.data) {
            const pagination = { ...this.pagination }
            pagination.total = resJson.Total
            this.pagination = pagination
          }
        })
    },
    onSelectChange (selectedRowKeys) {
      this.selectedRowKeys = selectedRowKeys
    },
    hasSelected () {
      return this.selectedRowKeys.length > 0
    },
    handleAdd () {
      this.$refs.editForm.openDrawer()
    },
    handleEdit (id) {
      this.$refs.editForm.openDrawer(id)
    },
    handleDelete (ids) {
      var thisObj = this
      this.$confirm({
        title: '确认删除吗?',
        onOk () {
          return new Promise((resolve, reject) => {
            thisObj.$http.post('/Base_VIPUser/Base_VIPUserOrder/DeleteData', ids).then(resJson => {
              resolve()

              if (resJson.Success) {
                thisObj.$message.success('操作成功!')

                thisObj.getDataList()
              } else {
                thisObj.$message.error(resJson.Msg)
              }
            })
          })
        }
      })
    },
    timeFormat (val) { // 时间格式化函数
      return moment(val).format('YYYY-MM-DD HH:mm')
    }
  }
}
</script>
<style scoped>
.statusFinish {
  padding: 5px 10px;
  color: white;
  border-radius: 3px;
  background-color: green;
}

.statusCalc {
  padding: 5px 10px;
  color: white;
  border-radius: 3px;
  background-color: red;
}
</style>
